package com.wing.product.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.product.dao.ProcessDeviceDao;
import com.wing.product.dao.ProcessLineTemplateDao;
import com.wing.product.model.entity.ProcessDevice;
import com.wing.product.model.entity.ProcessLineTemplate;
import com.wing.product.model.request.ProcessDeviceForm;
import com.wing.product.model.response.ProcessDeviceVO;
import com.wing.product.model.response.ProcessInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 工艺线路模板-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class ProcessLineTemplateServiceImpl extends ServiceImpl<ProcessLineTemplateDao, ProcessLineTemplate> implements ProcessLineTemplateService {

    @Override
    public Page<ProcessLineTemplate> list(Page<ProcessLineTemplate> page, Map<String, Object> params) {
        List<ProcessLineTemplate> list = baseMapper.list(page, params);
        page.setRecords(list);
        return page;
    }


    /**
     * 查询模板关联的工艺
     * @param pg
     * @param queryParam
     * @return
     */
    @Override
    public IPage<ProcessInfoVO> listAndProcess(Page<ProcessInfoVO> pg, Map queryParam) {
        List<ProcessInfoVO> list = baseMapper.listAndProcess(pg,queryParam);
        return pg.setRecords(list);
    }

    /**
     * 删除模板绑定的工序
     * @param processLineTemplateId
     * @param processId
     * @return
     */
    @Override
    public boolean deleteTempForProcess(Long processLineTemplateId, Long processId) {
        return baseMapper.deleteTempForProcess(processLineTemplateId,processId);
    }

    /**
     * 删除工序模板
     * @param processLineTemplateId 工序模板
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long processLineTemplateId) {
        boolean b = this.removeById(processLineTemplateId);
        if (b){
            //删除绑定的
            baseMapper.deleteTempForProcessAll(processLineTemplateId);
            return true;
        }
        return false;
    }
}
